<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var person ={
        personName:"zhangsan",
        age:20,
        sayHello: function(){
            console.log("hello");
        }
    }
    //  第一种写法，最常用写法，对象.属性名
    // 对象，方法名
    console.log(person.age);
    person.sayHello();

    //第二种写法   对象["属性名"]
    console.log(person["personName"]);
    person["sayHello"]();

    //区别  对象[变量]中括号中可以放变量

    var attr ="age";
    console.log(person[attr]);
    //访问对象不存在的属性，打印的是undefined
    console.log(person.hobby);

//添加hobby属性
    person.hobby =["swimming","football"];
    console.log(person.hobby);
    //添加一个体重
    person["weight"]="60kg";
    console.log(person["weight"]);
    //修改属性值

    person.age =30;
    person["age"]=30;

    delete person.age;
    console.log(person.age);
    </script>
</html>